package com.job.search.controller;

import com.job.client.common.result.ResponseResult;
import com.job.search.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RequestMapping("/api/v1/search")
@RestController
@Api(tags = "综合搜索服务接口")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @PostMapping("/getPostsCompanyByName")
    @ApiOperation("根据name查找es中公司和职位的数据，并把数据高亮显示")
    public ResponseResult getPostsCompanyByName(@RequestBody String name){
        return searchService.getPostsCompanyByName(name);
    }

    @PostMapping("/saveHistory")
    @ApiOperation("用户搜索的内容保存到历史记录")
    public ResponseResult saveHistory(@RequestBody String content, HttpServletRequest request){
        return searchService.saveHistory(content,request);
    }
    @GetMapping("/getHistory")
    @ApiOperation("获得用户的搜索记录")
    public ResponseResult getHistory(HttpServletRequest request){
        return searchService.getHistory(request);
    }

    @DeleteMapping("/clearHistory")
    @ApiOperation("清空历史历史搜索记录")
    public ResponseResult clearHistory(HttpServletRequest request){
        return searchService.clearHistory(request);
    }
    @GetMapping("/getSearchContent")
    @ApiOperation("获得当前城市匹配关键字的职位和公司，职位模糊匹配，公司精确匹配")
    public ResponseResult getSearchContent(@RequestParam String key,@RequestParam String city){
        return searchService.getSearchContent(key,city);
    }
}
